<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php require("../../config/config.php") ?>
<title><?php echo $title ?></title>
</head>

<body>
<?php require("../../include/db_connect.php") ?>
<?php //require("../../include/topbar.php") ?>
<?php require("../../include/xmlReader.php") ?>
<?php
$entity = $_GET['entity'];
$vals = retrieve("../../knowledgebase/".$entity.".xml");

?>
<form name="frmIndexCrib" action="" method="post">

<br>
<table align="center" border="1" cellpadding="3" cellspacing="0" width="977">
	<tr>
		<td class="bigtableheader" colspan="2">Credit Note List</td>
		<td class="cleartable">
			<a href="credit_note_list.php?module=Invoicing&invoice_type=<? echo $invoice_type ?>&selMonth=<? echo $prevMonth ?>&selYear=<? echo $prevYear ?>">&lt;&lt;</a>
			<?php echo getMonthName($selMonth)." - ".$selYear; ?>
			<a href="credit_note_list.php?module=Invoicing&invoice_type=<? echo $invoice_type ?>&selMonth=<? echo $nextMonth ?>&selYear=<? echo $nextYear ?>">&gt;&gt;</a>
		</td>
		<td colspan="5" align="right" class="cleartable"><a class="tableheaderlink" href="credit_note_details.php?module=Invoicing&invoice_type=<? echo $invoice_type ?>&mode=new">New</a></td>
	</tr>
	<tr class="tableheader">
		<td width="109" class="sortField" onclick="frmSimpleAccounts.sortField.value ='inv_id'; frmSimpleAccounts.submit();">Credit Note Id </td>
		<td width="102" class="sortField" onclick="frmSimpleAccounts.sortField.value ='inv_date'; frmSimpleAccounts.submit();">Date</td>
		<td width="232" class="sortField" onclick="frmSimpleAccounts.sortField.value ='cname'; frmSimpleAccounts.submit();">Customer</td>
		<td width="91" class="sortField" onclick="frmSimpleAccounts.sortField.value ='total_amount'; frmSimpleAccounts.submit();">Zero-Rated</td>
		<td width="91" class="sortField" onclick="frmSimpleAccounts.sortField.value ='total_amount'; frmSimpleAccounts.submit();">Taxable</td>
		<td width="91" class="sortField" onclick="frmSimpleAccounts.sortField.value ='total_amount'; frmSimpleAccounts.submit();">GST</td>
		<td width="95" class="sortField" onclick="frmSimpleAccounts.sortField.value ='total_amount'; frmSimpleAccounts.submit();">Total Amount</td>
		<td width="100">Paid</td>
	</tr>
	<?php $result = getCreditNoteReport("", $dateFrom, $dateTo,"inv_id","ASC") ?>
	<?php while($row = mysql_fetch_assoc($result)){ ?>
	<tr class="tablerow" onclick="window.navigate('credit_note_details.php?module=Invoicing&invoice_type=<? echo $invoice_type ?>&mode=edit&inv_id=<?php echo $row['inv_id'] ?>')">
		<td width="109"><?php echo $row['inv_id'] ?></td>
		<td width="102"><?php echo $row['inv_date'] ?>&nbsp;</td>
		<td width="232"><?php echo $row['cname'] ?>&nbsp;</td>
		<td><?php echo $row['zero_rated'] ?></td>
		<?php $z += $row['zero_rated'] ?>
		<td><?php echo $row['taxable'] ?></td>
		<?php $t += $row['taxable'] ?>
		<td><?php echo $row['gst_amount'] ?></td>
		<?php $g += $row['gst_amount'] ?>
		<td><?php echo $row['total_amount'] ?></td>
		<?php $ta += $row['total_amount'] ?>
		<td><?php if(isCreditNotePaid($row['inv_id']) == false){ echo "<a href='credit_pay_details.php?module=Invoicing&mode=new&credit_note=".$row['inv_id']."'>Pay</a>"; }else{ echo "&nbsp;"; } ?></td>
	</tr>
		<?php $credit_pay_id = getCreditPayIdForCreditNote($row['inv_id']); ?>
		<?php if(strlen($credit_pay_id) > 0){ ?>
			<?php $result2 = getCreditPay($credit_pay_id); ?>
			<?php while($row2 = mysql_fetch_assoc($result2)){ ?>
			<tr bgcolor="#CCCCCC" class="tablerow" onclick="window.navigate('credit_pay_details.php?module=Invoicing&mode=edit&credit_pay_id=<?php echo $credit_pay_id ?>&credit_note=<?php echo $row['inv_id'] ?>')">
				<td width="109"><?php echo $credit_pay_id; ?></td>
				<td width="102"><?php echo $row2['payment_date'] ?>&nbsp;</td>
				<td width="232"><?php echo $row['cname'] ?>&nbsp;</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td><?php echo $row2['amount'] ?></td>
  </tr>
			<?php } ?>
		<?php } ?>
	<?php } ?>
	<tr class="tableheader">
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td align="right"><?php echo number_format($z,2,".",","); ?></td>
			<td align="right"><?php echo number_format($t,2,".",","); ?></td>
			<td align="right"><?php echo number_format($g,2,".",","); ?></td>
			<td align="right"><?php echo number_format($ta,2,".",","); ?></td>
			<td>&nbsp;</td>
</table>

</body>
</html>
